package com.ptu.controller.user;

import com.github.pagehelper.PageInfo;
import com.ptu.context.BaseContext;
import com.ptu.dto.CommentPageQueryDTO;
import com.ptu.entity.Comment;
import com.ptu.result.Result;
import com.ptu.service.CommentService;
import com.ptu.vo.CommentVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController("userCommentController")
@RequestMapping("/user/comment")
@Api(tags = "评论相关接口")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 新增评论
     * @param comment
     * @return
     */
    @PostMapping
    @ApiOperation("新增评论")
    public Result save(@RequestBody Comment comment) {
        comment.setUsersId(BaseContext.getCurrentId());
        comment.setCommentTime(LocalDateTime.now());
        commentService.save(comment);
        return Result.success();
    }

    /**
     * 根据订单id查询评论
     * @param orderId
     * @return
     */
    @GetMapping("/queryByOrderId/{orderId}")
    @ApiOperation("根据订单id查询评论")
    public CommentVO getOrderById(@PathVariable Long orderId) {
        return commentService.getByOrderId(orderId);
    }

    @GetMapping("/queryByStoreId/{storeId}")
    @ApiOperation("根据店铺id查询评论")
    public List<CommentVO> getByStoreId(@PathVariable Long storeId) {
        return commentService.getByStoreId(storeId);
    }

}